Skip to content

fix: return empty string for non-positive TruncateWords maxWords - #4

Closed
rune-gh wants to merge 1 commit into
go-pkgz:masterfrom
rune-gh:fix/truncate-words-negative
Closed

rune-gh wants to merge 1 commit into
go-pkgz:masterfrom
rune-gh:fix/truncate-words-negative

Conversation

@rune-gh

@rune-gh rune-gh commented Oct 5, 2026

Copy link
Copy Markdown

Summary

TruncateWords only special-cased maxWords == 0. A negative maxWords skipped that guard, failed the len(words) <= maxWords check, and then panicked on words[:maxWords] (slice bounds out of range).

Treat any non-positive maxWords the same as zero and return "", matching the defensive behavior of Truncate.

Test plan

  • Added regression case for maxWords: -1
  • go test ./...

@rune-gh
rune-gh requested a review from umputun as a code owner October 5, 2026 21:02
@umputun umputun closed this Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants